$(document).ready(function() {
	$(".excluir-analista").live('click', function() {
		$(this).parent().remove();
	});
	$(".analista").live();
	
	$(".excluir-gerente").live('click', function() {
		$(this).parent().remove();
	});
	$(".gerente").live();
	
	$(".excluir-desenvolvedor").live('click', function() {
		$(this).parent().remove();
	});
	$(".desenvolvedor").live();
	
	$("#clientes").live();				//auto complete do modal adiciona cliente
	
	$(".excluir-cliente").live('click', function() { 	//class do botao de remocao
		$(this).parent().remove();
	});	
	$(".cliente").live();
	
	
	$.getJSON("../services/autocomplete_service/get_colaboradores", function(data) {
		$("#novo_analista").autocomplete({
			source: data,
			select: function(event, ui) {
				$("#analistas").append("<div class='analista'>" + 
						"<input name='analista[]' value='" + ui.item.value + "'>"+
						"<button class='excluir-analista' href='#'>X</button></div>");
			
			},
			close: function () {
				$(this).val("");
			}
		});
	});
	
	$.getJSON("../services/autocomplete_service/get_colaboradores", function(data) {
		$("#novo_gerente").autocomplete({
			source: data,
			select: function(event, ui) {
				//alert(ui.item.value);
				$("#gerentes").append("<div class='gerente'>" + 
						"<input  name='gerente[]' value='" + ui.item.value + "'>" +
						"<button class='excluir-gerente' href='#'>X</button></div>");
				$(":input").live();
			
			},
			close: function () {
				$(this).val("");
			}
		});
	});
	
	$.getJSON("../services/autocomplete_service/get_colaboradores", function(data) {
		$("#novo_desenvolvedor").autocomplete({
			source: data,
			select: function(event, ui) {
				$("#desenvolvedores").append("<div class='desenvolvedor'>" + 
						"<input value='" + ui.item.value + "'>" + 
						"<button class='excluir-desenvolvedor' href='#'>X</button>" + 
						"<input type='hidden' name='desenvolvedor[]' value='" + ui.item.id + "'>" + 
						"</div>");
			},
			close: function () {
				$(this).val("");
			}
		});
	});
	
	/*$.getJSON("../services/autocomplete_service/get_colaboradores", function(data) {
		$("#consulta_cliente").autocomplete({
			source: data,
			select: function(event, ui) {
				$.getJSON("../services/autocomplete_service/get_colaborador_by_id" + ui.item.id, function(data) {
					$("#clientes").append("<div class='cliente'>Nome: <input disabled='disabled' name='cliente' value='" + data.value + "'><br>Id: <input disabled='disabled' name='id' value='" + data.id + "'><br>" +
																	"Responsavel: <input disabled='disabled' name='responsavel' value='" + data.responsavel + "'><br>Cabelo: <input disabled='disabled' name='cabelo' value='" + data.cabelo + "'>"+
																	"<br><br><input type='submit' value='Confirmar cliente'></div>");
				});
			}
		});
	});*/
	
	$.getJSON("../services/autocomplete_service/get_colaboradores", function(data) {
		$("#idCliente").autocomplete({
			source: data,
		});
	});
});